﻿module Combinators

open Microsoft.FSharp.Quotations

let S<'a>= <@ fun f g x -> f x (g x) @>
let I<'a> = <@ fun x -> x @>
let K<'a> = <@ fun x y -> x @>

// let Y = <@ fun S K I -> S (K (S I I)) (S (S (K S) K) (K (S I I))) @>

type CombinatorTerm =
    | Kcomb
    | Scomb
    | Icomb
    | Capp of CombinatorTerm * CombinatorTerm

type CombinatorExtension<'a> =
    | KEcomb
    | SEcomb
    | IEcomb
    | CEvar of 'a

    member this.IsVar =
        match this with
        | CEvar _ -> true
        | _ -> false

    override this.ToString() =
        match this with
        | KEcomb -> "K"
        | SEcomb -> "S"
        | IEcomb -> "I"
        | CEvar(var) -> sprintf "%O" var